def check_no_intersection(tuples):
    """
    Check if paths from tuples with the same num have any intersection, with optimized time complexity.
    元组集合[(),(),()]，其中元组的结构为（num,list1,list2），num为int，list1和list2中的元素都是int
    路径：list1中的元素->list2中的元素称为路径，例如list1=[1,2],list2=[2,3],则路径有四条，分别是1->2,1->3,2->2,2->3
    要求：如果元组之间num相同，则路径不能有交集

    Args:
    tuples (list of tuples): A list of tuples in the form (num, list1, list2) where num is an int and list1, list2 are lists of ints.



    Returns:
    bool: True if no intersection, False otherwise.
    """
    path_dict = {}

    for num, list1, list2 in tuples:
        # Create a set of paths for the current tuple
        current_paths = set((i, j) for i in list1 for j in list2)

        # If the num is already in the path_dict, check for intersection
        if num in path_dict:
            if path_dict[num] & current_paths:  # Intersection found
                return False
            path_dict[num].update(current_paths)
        else:
            path_dict[num] = current_paths

    return True


def is_continuous(intervals):
    """
    判断形如[(1, 3), (3, 5), (5, 7)]的区间集合是否是连续的，如果是的话，输出上确界和下确界

    Determine if a set of intervals is continuous and find the infimum and supremum.

    Args:
        intervals (list of tuples): A list of intervals in the form (left, right) where the interval is left-open and right-closed.

    Returns:
        is_continuous, inf, sup
    """
    if not intervals:
        return False, None, None

    intervals.sort(key=lambda x: x[0])  # 对区间进行排序
    inf = intervals[0][0]  # 初始化下确界
    sup = intervals[0][1]  # 初始化上确界

    # 检查区间是否连续
    for i in range(1, len(intervals)):  # 从第二个区间开始
        if intervals[i][0] > sup:  # 如果当前区间的最小值，大于上确界，表示有间隔
            return False, inf, sup

        sup = max(sup, intervals[i][1])  # 更新最大上确界

    return True, inf, sup


def check_intersection_with_details(tuples):
    """
    Check if paths from tuples with the same num1 and num2 have any intersection, and return details about those paths.
    元组集合[(),(),(),()]，其中元组的结构为（num1,num2,list1,list2），num1为int，num2为int，list1和list2中的元素都是int
    路径：list1中的元素->list2中的元素称为路径，例如list1=[1,2],list2=[2,3],则路径有四条，分别是1->2,1->3,2->2,2->3
    要求：如果元组之间num1、num2都相同，且路径有交集则判定为重复，返回True/False，同时返回元组集合

    Args:
        tuples (list of tuples): A list of tuples in the form (num1, num2, list1, list2) where num1, num2 are integers and list1, list2 are lists of integers.

    Returns:
        dict: A dictionary containing:
              'has_intersection' (bool): True if there is an intersection, False otherwise.
              'intersections' (dict): Keys are (num1, num2) tuples, values are sets of intersecting paths.
    """
    path_dict = {}
    intersections = {}

    for num1, num2, list1, list2 in tuples:
        current_paths = set((i, j) for i in list1 for j in list2)
        num_pair = (num1, num2)

        if num_pair in path_dict:
            intersecting_paths = path_dict[num_pair] & current_paths
            if intersecting_paths:
                if num_pair not in intersections:
                    intersections[num_pair] = set()
                intersections[num_pair].update(intersecting_paths)
            path_dict[num_pair].update(current_paths)
        else:
            path_dict[num_pair] = current_paths

    return {
        'has_intersection': bool(intersections),
        'intersections': intersections
    }
